package com.example.a14110100420.yuejian.WActivity.personal;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.Toast;

import com.example.a14110100420.yuejian.R;
import com.example.a14110100420.yuejian.WAdapter.personal.MyFatieListAdapter;
import com.example.a14110100420.yuejian.WSerivice.PersonalService;
import com.example.a14110100420.yuejian.Wbase.BaseActivity;
import com.example.a14110100420.yuejian.Wbase.Conast;
import com.example.a14110100420.yuejian.Wbean.personal.ShowPictureList;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class FatieDetailActivity extends AppCompatActivity {
    final String userid = BaseActivity.getUserid();

    private RecyclerView recyclerView;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_fatie_detail);
        getSupportActionBar().hide();//隐藏ActionBar
        getFatieList();


    }
    private void getFatieList(){
        recyclerView = (RecyclerView) findViewById(R.id.fatie);
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(Conast.base_Url)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        PersonalService service = retrofit.create(PersonalService.class);
        Call<List<ShowPictureList>> call = service.showById(userid);
        call.enqueue(new Callback<List<ShowPictureList>>() {
            @Override
            public void onResponse(Call<List<ShowPictureList>> call, Response<List<ShowPictureList>> response) {
                List<ShowPictureList> showPictureLists = response.body();
                if (response.isSuccessful()){
                    LinearLayoutManager layoutManager= new LinearLayoutManager(FatieDetailActivity.this);
                    layoutManager.setOrientation(LinearLayoutManager.VERTICAL);

                    recyclerView.setLayoutManager(layoutManager);
                    recyclerView.setAdapter(new MyFatieListAdapter(FatieDetailActivity.this,showPictureLists));
                    recyclerView.setItemAnimator(new DefaultItemAnimator());
                }

            }

            @Override
            public void onFailure(Call<List<ShowPictureList>> call, Throwable t) {
                Toast.makeText(FatieDetailActivity.this,"失败",Toast.LENGTH_SHORT).show();

            }
        });
    }
}
